#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/7/1 23:05
# @Author : linjinting
# @Project : PW4Adatatool
# @File : handle_base.py
# @Software: PyCharm

from mysql_model.mysql_connection import MysqlConnection


class HandleBase(object):
    def __init__(self, config_=None, **kwargs):
        if config_ is None:
            return
        self.m_config = config_
        self.m_connection = MysqlConnection(self.m_config, **kwargs)
        self.m_connection.connect()
        self.m_tableName = None

    def connect(self):
        self.m_connection.connect()

    def isConnected(self):
        return self.m_connection.isConnected()

    def set_connection(self, conn):
        self.m_connection = conn

    def get_connection(self):
        return self.m_connection

    def get_data(self, tableName, fields_):
        if not self.m_connection.isConnected():
            self.m_connection.connect()
        _sql, _values = MysqlConnection.genSelectSQL(tableName, fields_)
        result = self.m_connection.select(_sql, _values)
        return result

    def insert_multiple_data(self, fields_, valueList):
        if self.m_connection.isConnected():
            self.m_connection.connect()
        _sql, _values = MysqlConnection.genInsertSQLMultiple(self.m_tableName, fields_, valueList)
        if not _values or not _sql:
            return -2
        ret = self.m_connection.insert_many(_sql, _values)
        return ret

class User4A(HandleBase):
    def __init__(self, config_=None):
        super().__init__(config_)
        # self.m_stationList = list()
        self.m_tableName = "t_user4a"

    def insert_user_data(self):
        tableName = "t_station"
        fields_ = ['userID', 'userDatas', 'loginName', 'realName', 'userStatus', 'bizOrgId', 'dutyRoles']
        return self.insert_multiple_data(tableName, fields_)